﻿using System;
using System.IO;
using System.Linq;
using System.Threading;

namespace FanaticGene.IOExtension
{
    public class PathEx
    {
        ///<summary>查找文件夹所在目录和相邻文件夹，并查询文件名。</summary>
        public static string? SeekFullFileName(string startPath, string targetFileName)
        {
            // startPath 开始路径。
            if (Directory.Exists(startPath))
            {

            }
            else if (File.Exists(startPath))
            {
                startPath = Path.GetDirectoryName(startPath);
            }

       
            for (int i = 0; i < 2; i++)
            {
                if (Path.IsPathRooted(startPath)) continue;
                startPath = Path.GetDirectoryName(startPath);
            }

            var files = Directory.GetFiles(startPath, targetFileName);
            return files.FirstOrDefault();
        }

    }
}
